package com.cxl.mapreduce._14index;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.lib.input.FileSplit;

import java.io.IOException;

/**
 * @author joyson
 * @create 2019-06-27-下午5:17
 */
public class OneIndexMapper extends Mapper<LongWritable, Text,Text, IntWritable> {
    String name;
    Text k=new Text();
    IntWritable v=new IntWritable(1);
    @Override
    protected void setup(Context context) throws IOException, InterruptedException {
        FileSplit inputSplit = (FileSplit) context.getInputSplit();
        name = inputSplit.getPath().getName();
    }

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        String line = value.toString();
        String[] fields= line.split(" ");
        for (String word:fields){
            k.set(word+"--"+name);
            context.write(k,v);
        }
    }
}
